/*
 * SpeciesMap.h
 *
 *  Created on: 15 Jul 2011
 *      Author: al2010
 */

#ifndef SPECIESMAP_H_
#define SPECIESMAP_H_

// C++ includes
#include <map>
#include <vector>
using namespace std;

// Boost includes
#include <boost/foreach.hpp>

// GeoReact includes
#include "Types.h"

class SpeciesMap 
{
public:
	SpeciesMap();
	
	template<class StringRange>
	SpeciesMap(const StringRange& speciesNames);
	
	inline const Index
	operator[](const string& speciesName) const;
	
	inline const vector<Index>
	operator[](const vector<string>& speciesNames) const;
	
private:
	map<string, Index> speciesMap;
};

template<class StringRange>
SpeciesMap::SpeciesMap(const StringRange& speciesNames)
{
	unsigned index = 0;
	
	BOOST_FOREACH(const string& species, speciesNames)
	{
		speciesMap.insert(std::make_pair(species, index));
		
		++index;
	}
}

const Index SpeciesMap::operator[](const string& speciesName) const
{
	return speciesMap.find(speciesName)->second;
}

const vector<Index> SpeciesMap::operator[](const vector<string>& speciesNames) const
{
	vector<Index> indexes; indexes.reserve(speciesNames.size());
	
	BOOST_FOREACH(const string speciesName, speciesNames)
		indexes.push_back( (*this)[speciesName] );
	
	return indexes;
}

#endif /* SPECIESMAP_H_ */
